package com.briup.day26_map;

import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;

/**
 * 模拟登录系统
 * */
public class MapDemo2 {
	
	static class student{
		
		private int id;
		private String username;
		private String password;
		public student(int id, String username, String password) {
			super();
			this.id = id;
			this.username = username;
			this.password = password;
		
		}
		public int getId() {
			return id;
		}
		public void setId(int id) {
			this.id = id;
		}
		public String getUsername() {
			return username;
		}
		public void setUsername(String username) {
			this.username = username;
		}
		public String getPassword() {
			return password;
		}
		public void setPassword(String password) {
			this.password = password;
		}
		
	}

	public static void main(String[] args) {
		
		
		login2();
		
		
		
	}
	
	public void login1() {
		List list = new ArrayList();
		list.add(new student(1001, "tom123", "123456"));
		list.add(new student(1002, "lisa123", "123123"));
		
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入您的账号：");
		String username = sc.nextLine();
		boolean flag = false;
		while (!flag) {
			for(Object object : list) {
				student stu = (student) object;
				if (stu.getUsername().equals(username)) {
					flag = true;
					break;
				}
			
			}
			if (!flag) {
				System.out.println("账号不存在");
				
			}

		}
		
		boolean flag2 = false;
		while (!flag2) {
			System.out.println("请输入您的密码:");
			String userpwd = sc.nextLine();
			for(Object object : list) {
				student stu = (student) object;
				if (stu.getUsername().equals(username)
						&& stu.getPassword().equals(userpwd)) {
					flag2 = true;
					break;
				}
			
			}
			if (!flag2) {
				System.out.println("密码输入错误");
			}
			
			
		}
		System.out.println("登录成功");
		
	}
	
	public static void login2() {
		Map<String,student> map = new HashMap<>();
		map.put("tom123", new student(1001, "tom123", "123456"));
		map.put("lisa123", new student(1002, "lisa123", "123123"));
		
		/*Scanner sc = new Scanner(System.in);
		String username = null;
		do {
			System.out.println("请输入您的账号：");
			username = sc.nextLine();
		} while (!map.containsKey(username));
		
		String password = null;
		student stu = map.get(username);
		do {
			System.out.println("请输入您的密码:");
			password = sc.nextLine();
		} while (!password.equals(stu.getUsername()));
		
		System.out.println("登录成功");*/
		
	//	loop1(map);
	//	loop2(map);
		loop3(map);
		
	}

	private static void loop3(Map map) {
		Set entryset = map.entrySet();
		for(Object object : entryset) {
			System.out.println(object);
		}

		
	}

	private static void loop2(Map map) {
		Collection collection = map.values();
		for(Object object : collection) {
			System.out.println(object );
		}
		
	}

	private static void loop1(Map map) {
		Set keyset = map.keySet();
		for(Object object : keyset) {
			System.out.println(object + "=" + map.get(object));
		}
		
	}

}
